﻿using System.Collections;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JUtil.CodeGenerator;

namespace CodeGenerator
{
    public class MasterViewAspxCsFile : CodeGenBase, ICSharpFile
    {
        public MasterViewAspxCsFile(CSharpFileSetting CSharpFileSetting)
        {
            NAMESPACE = CSharpFileSetting.NAMESPACE;
            CLASS = CSharpFileSetting.ASPX_CLASS;
            DAL_CLASS = CSharpFileSetting.DAL_CLASS;
            BLL_CLASS = CSharpFileSetting.BLL_CLASS;
        }

        private readonly string NAMESPACE;
        private readonly string CLASS;
        private readonly string DAL_CLASS;
        private readonly string BLL_CLASS;

        protected override void AssignExportTemplate(Hashtable Variables)
        {
            Variables["USING_NAMESPACES"] = USING_NAMESPACES;
            Variables["NAMESPACE"] = GetNameSpace();
            Variables["CLASS"] = GetClass();
            Variables["DAL_CLASS"] = DAL_CLASS;
            Variables["BLL_CLASS"] = BLL_CLASS;
        }

        protected override string GetExportTemplate()
        {
            return GetTemplate("ExportTemplate");
        }

        #region ICSharpFile 成員

        public string USING_NAMESPACES
        {
            get
            {
                List<string> lstUsingNameSpace = new List<string>
                {
                    "JUtil.Web.Extensions",
                    "JUtil.Extensions",
                    "System",
                    "System.Collections.Generic",
                    "System.Linq",
                    "System.Web",
                    "System.Web.UI",
                    "System.Web.UI.WebControls",
                    "System.Collections.Specialized",
                    "JUtil",
                    "System.Reflection"
                };

                StringBuilder output = new StringBuilder();

                foreach (string ns in lstUsingNameSpace)
                {
                    output.AppendFormat("using {0};\n", ns);
                }

                output.AppendFormat("using {0};\n", GetNameSpace());

                return output.ToString();
            }
        }

        public string GetNameSpace()
        {
            return NAMESPACE;
        }

        public string GetClass()
        {
            return CLASS;
        }

        #endregion
    }
}
